<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP TdLib</title>
    <!-- Meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800'
          rel='stylesheet' type='text/css'>
    <!-- FontAwesome JS -->
    <script defer src="https://use.fontawesome.com/releases/v5.1.1/js/all.js"
            integrity="sha384-BtvRZcyfv4r0x/phJt9Y9HhnN5ur1Z+kZbKVgzVBAlQZX4jvAuImlIz+bG7TS00a"
            crossorigin="anonymous"></script>
    <!-- Global CSS -->
    <link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
    <!-- Plugins CSS -->
    <link rel="stylesheet" href="assets/plugins/prism/prism.css">
    <link rel="stylesheet" href="assets/plugins/elegant_font/css/style.css">

    <!-- Theme CSS -->
    <link id="theme-style" rel="stylesheet" href="assets/css/styles.css">

</head>

<body class="body-pink">
<div class="page-wrapper">
    <!-- ******Header****** -->
    <header id="header" class="header">
        <div class="container">
                <span style="font-size: 3em; position:absolute; top:20px; right:40px">
                    <a href="https://github.com/yaroslavche/phptdlib" target="_blank"><i class="fab fa-github"></i></a>
                </span>
            <div class="branding">
                <h1 class="logo">
                    <a href="index.html">
                        <span aria-hidden="true" class="fa fa-paper-plane icon"></span>
                        <span class="text-highlight">PHP</span><span class="text-bold">TdLib</span>
                    </a>
                </h1>
            </div><!--//branding-->
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                <li class="breadcrumb-item active">Installation</li>
            </ol>
        </div><!--//container-->
    </header><!--//header-->
    <div class="doc-wrapper">
        <div class="container">
            <div id="doc-header" class="doc-header text-center">
                <h1 class="doc-title"><i class="icon icon_cogs"></i> Installation</h1>
                <div class="meta"><i class="far fa-clock"></i> Last updated: February 19, 2020</div>
            </div><!--//doc-header-->
            <div class="doc-body row">
                <div class="doc-content col-md-9 col-12 order-1">
                    <div class="content-inner">
                        <section id="installation-section" class="doc-section">
                            <h2 class="section-title">Installation</h2>
                            <div class="callout-block callout-info">
                                <div class="icon-holder">
                                    <i class="fas fa-info-circle"></i>
                                </div><!--//icon-holder-->
                                <div class="content">
                                    <h4 class="callout-title">Note</h4>
                                    <p>The most of dependencies are installed via git submodules currently.
                                        But PHP-CPP currently has to be built separately.</p>
                                </div><!--//content-->
                            </div><!--//callout-block-->

                            <div id="php-cpp" class="section-block">
                                <h3 class="block-title">CopernicaMarketingSoftware/PHP-CPP</h3>
                                <div class="code-block">
<pre><code class="language-bash">git clone https://github.com/CopernicaMarketingSoftware/PHP-CPP.git
cd PHP-CPP
make
sudo make install</code></pre>
                                </div><!--//code-block-->
                            </div><!--//section-block-->
                            <div id="phptdlib" class="section-block">
                                <h3 class="block-title">yaroslavche/phptdlib</h3>
                                <div class="callout-block callout-info">
                                    <div class="icon-holder">
                                        <i class="fas fa-info-circle"></i>
                                    </div><!--//icon-holder-->
                                    <div class="content">
                                        <h4 class="callout-title">Note</h4>
                                        <p>
                                            If you want to link other dependencies as dynamic libraries, you can pass
                                            some options to cmake. Look through <a
                                                href="https://github.com/yaroslavche/phptdlib/blob/master/CMakeLists.txt">CMakeLists.txt</a>
                                            comments to find out how.
                                            Required more than <a href="https://github.com/tdlib/td/issues/67">4GB
                                            RAM</a> and must wait a while.
                                        </p>
                                    </div><!--//content-->
                                </div><!--//callout-block-->
                                <div class="code-block">
<pre><code class="language-bash">git clone --recurse-submodules https://github.com/yaroslavche/phptdlib.git
cd phptdlib && mkdir build && cd build
cmake ..
make
sudo make install</code></pre>
                                </div><!--//code-block-->
                            </div><!--//section-block-->
                            <div id="ubuntu-bionic-beaver" class="section-block">
                                <h3 class="block-title">Full installation example on Ubuntu 18.04</h3>
                                <div class="code-block">
                                    Go to some dir where phptdlib and PHP-CPP dirs will be placed:
                                    <pre><code class="language-bash">
$ cd ~/projects</code></pre>
                                    Install required dependencies:
                                    <pre><code class="language-bash">
$ sudo apt install gperf zlib1g-dev php-all-dev</code></pre>
                                    Clone and build PHP-CPP:
                                    <pre><code class="language-bash">
$ git clone https://github.com/CopernicaMarketingSoftware/PHP-CPP.git
$ cd PHP-CPP
$ make
$ sudo make install</code></pre>
                                    Return back into installation dir:
                                    <pre><code class="language-bash">
$ cd ../</code></pre>
                                    Clone and build phptdlib:
                                    <pre><code class="language-bash">
$ git clone --recurse-submodules https://github.com/yaroslavche/phptdlib.git
$ cd phptdlib && mkdir build && cd build
$ cmake ..
$ make
$ sudo make install</code></pre>
                                    And check if it works:
                                    <pre><code class="language-bash">
$ php -m | grep tdlib
$ php ../php_examples/func.php
$ php -r "echo (function_exists('td_json_client_create') ? 'ok' : 'failed') . PHP_EOL;"</code></pre>
                                </div><!--//code-block-->
                            </div><!--//section-block-->
                            <div id="scripts-install" class="section-block">
                                <h3 class="block-title">Installation with shared libraries</h3>
                                <div class="code-block">
                                    This way of installation using in travis. And this can be useful and simpler than other ways. Let's say, we have installed and configured cmake with gcc (9). Need just specify 3 env variables (CONFIG, CC and GCC) and run <b>./scripts/install.sh</b>
                                    <pre><code class="language-bash">
$ CONFIG=gcc CC=gcc CXX=g++ ./scripts/install.sh</code></pre>
                                    This will clone modules into cached_builds directory, build it and install (requires sudo). Then you can always run this command for easy module updates.<br>
                                    After success modules installation can continue to install extension. Same way as above, just with one difference: need specify cmake flags:
                                    <pre><code class="language-bash">
$ cmake -D USE_SHARED_TD:BOOL=ON -D USE_SHARED_JSON:BOOL=ON -D USE_SHARED_PHPCPP:BOOL=ON ..</code></pre>
                                    So, full command list:
                                    <pre><code class="language-bash">
$ git clone https://github.com/yaroslavche/phptdlib.git && cd phptdlib
$ CONFIG=gcc CC=gcc CXX=g++ ./scripts/install.sh
$ mkdir build && cd build
$ cmake -D USE_SHARED_TD:BOOL=ON -D USE_SHARED_JSON:BOOL=ON -D USE_SHARED_PHPCPP:BOOL=ON ..
$ make
$ sudo make install</code></pre>
                                </div><!--//code-block-->
                            </div><!--//section-block-->
                        </section><!--//doc-section-->


                    </div><!--//content-inner-->
                </div><!--//doc-content-->
                <div class="doc-sidebar col-md-3 col-12 order-0 d-none d-md-flex">
                    <div id="doc-nav" class="doc-nav">
                        <nav id="doc-menu" class="nav doc-menu flex-column sticky">
                            <a class="nav-link scrollto" href="#installation-section">Installation</a>
                            <nav class="doc-sub-menu nav flex-column">
                                <a class="nav-link scrollto" href="#php-cpp">CopernicaMarketingSoftware/PHP-CPP</a>
                                <a class="nav-link scrollto" href="#phptdlib">yaroslavche/phptdlib</a>
                                <a class="nav-link scrollto" href="#ubuntu-bionic-beaver">Installation example on Ubuntu
                                    18.04</a>
                                <a class="nav-link scrollto" href="#scripts-install">scripts/install.sh</a>
                            </nav><!--//nav-->
                        </nav><!--//doc-menu-->
                    </div>
                </div><!--//doc-sidebar-->
            </div><!--//doc-body-->
        </div><!--//container-->
    </div><!--//doc-wrapper-->

</div><!--//page-wrapper-->

<footer id="footer" class="footer text-center">
    <div class="container">
        <div class="row">
            <div class="col-md-4">
                <!-- GITHUB BUTTON JS -->
                <script async defer src="https://buttons.github.io/buttons.js"></script>
                <a class="github-button" href="https://github.com/yaroslavche/phptdlib" data-size="small"
                   aria-label="Star yaroslavche/phptdlib on GitHub">Star</a>
            </div>
            <div class="col-md-4">
                <!--/* This template is released under the Creative Commons Attribution 3.0 License. Please keep the attribution link below when using for your own project. Thank you for your support. :) If you'd like to use the template without the attribution, you can buy the commercial license via our website: themes.3rdwavemedia.com */-->
                <small class="copyright">Designed with <i class="fas fa-heart"></i> by <a
                        href="https://themes.3rdwavemedia.com/" target="_blank">Xiaoying Riley</a> for developers
                </small>
            </div>
            <div class="col-md-4" style="overflow: hidden;height: 50px;margin-top: -15px;">
                <!-- JetBrains logo -->
                <a href="https://www.jetbrains.com/?from=phptdlib" style="margin-top: -24px; position: absolute;"><svg width="100px" height="100px" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120.21259 130.10278">
                    <title>JetBrains</title>
                    <g>
                        <path d="M120.21249,68.6a4.9968,4.9968,0,0,0-1.4-3.5L55.20349,2.68736a7.86372,7.86372,0,0,0-3.36731-2.261c-.03467-.012-.06812-.02612-.103-.03766-.19336-.06323-.3913-.11511-.591-.16327-.06689-.0163-.13177-.0368-.1994-.05133-.18744-.04-.37909-.06738-.57117-.09363-.0788-.0108-.15527-.0274-.23492-.03589A7.839,7.839,0,0,0,49.31249,0a7.73961,7.73961,0,0,0-1.21088.10413c-.0235.00391-.04694.00671-.07037.0108a7.62573,7.62573,0,0,0-3.092,1.24969c-.07343.04773-.155.08575-.22668.13538L4.91249,28.3c-.08221.08221-.15106.10632-.17773.16437L4.68467,28.5H4.61249A11.11647,11.11647,0,0,0,.17127,39.45685l.00854.04449c.05176.28589.11011.56958.18372.84973.03052.119.06964.235.104.35284.054.181.10278.3634.16571.5412A11.15109,11.15109,0,0,0,5.31249,47.1a8.8203,8.8203,0,0,0,2,.9c.4.2,45.4,18.8,45.4,18.8a4.291,4.291,0,0,0,4.4-7.3c-.06525,0-16.839-13.21332-28.69928-22.52606l21.105-19.03113,57.91815,49.58282L28.61249,110.7a9.82332,9.82332,0,0,0-4.7,4.1,10.06619,10.06619,0,0,0,3.44961,13.81148q.07481.04491.15039.08852a10.28687,10.28687,0,0,0,10.7-.2c.2-.2.5-.3.7-.5l78-54.8a18.32022,18.32022,0,0,0,1.58611-1.2663A4.74576,4.74576,0,0,0,120.21249,68.6Z" fill="#fff"/>
                        <g id="_Group_" data-name=" Group ">
                            <rect id="_Path_" data-name=" Path " x="34.61249" y="37.4" width="51" height="51"/>
                            <rect id="_Path_2" data-name=" Path 2" x="39.0125" y="78.8" width="19.1" height="3.2" fill="#fff"/>
                            <g id="_Group_2" data-name=" Group 2">
                                <path id="_Path_3" data-name=" Path 3" d="M38.81249,50.8l1.5-1.4a1.70272,1.70272,0,0,0,1.3.8q.9,0,.9-1.2V43.7h2.3V49a2.79543,2.79543,0,0,1-3.1,3.1A3.026,3.026,0,0,1,38.81249,50.8Z" fill="#fff"/>
                                <path id="_Path_4" data-name=" Path 4" d="M45.31249,43.8h6.7v1.9h-4.4V47h4v1.8h-4v1.3h4.5v2h-6.7Z" fill="#fff"/>
                                <path id="_Path_5" data-name=" Path 5" d="M55.01249,45.8h-2.5v-2h7.3v2h-2.5v6.3h-2.3Z" fill="#fff"/>
                                <path id="_Compound_Path_" data-name=" Compound Path " d="M39.0125,54h4.3a3.70232,3.70232,0,0,1,2.3.7,1.97823,1.97823,0,0,1,.5,1.4h0a1.95538,1.95538,0,0,1-1.3,1.9,1.94762,1.94762,0,0,1,1.6,2h0c0,1.4-1.2,2.3-3.1,2.3h-4.3Zm4.8,2.6c0-.5-.4-.7-1-.7h-1.5v1.5h1.4C43.4125,57.3,43.81249,57.1,43.81249,56.6Zm-.8,2.4h-1.8v1.5h1.8c.7,0,1.1-.3,1.1-.8h0C44.11249,59.2,43.7125,59,43.0125,59Z" fill="#fff"/>
                                <path id="_Compound_Path_2" data-name=" Compound Path 2" d="M46.81249,54h3.9a3.51462,3.51462,0,0,1,2.7.9,2.48948,2.48948,0,0,1,.7,1.9h0a2.76052,2.76052,0,0,1-1.7,2.6l2,2.9h-2.6l-1.7-2.5h-1v2.5h-2.3Zm3.8,4c.8,0,1.2-.4,1.2-1h0c0-.7-.5-1-1.2-1h-1.5v2Z" fill="#fff"/>
                                <path id="_Compound_Path_3" data-name=" Compound Path 3" d="M56.81249,54h2.2l3.5,8.4h-2.5l-.6-1.5h-3.2l-.6,1.5h-2.4Zm2,5-.9-2.3-.9,2.3Z" fill="#fff"/>
                                <path id="_Path_6" data-name=" Path 6" d="M62.81249,54h2.3v8.3h-2.3Z" fill="#fff"/>
                                <path id="_Path_7" data-name=" Path 7" d="M65.7125,54h2.1l3.4,4.4V54h2.3v8.3h-2l-3.5-4.5v4.6h-2.3Z" fill="#fff"/>
                                <path id="_Path_8" data-name=" Path 8" d="M73.7125,61.1l1.3-1.5a3.94222,3.94222,0,0,0,2.7,1c.6,0,1-.2,1-.6h0c0-.4-.3-.5-1.4-.8-1.8-.4-3.1-.9-3.1-2.6h0c0-1.5,1.2-2.7,3.2-2.7a5.33073,5.33073,0,0,1,3.4,1.1l-1.2,1.6a4.55349,4.55349,0,0,0-2.3-.8c-.6,0-.8.2-.8.5h0c0,.4.3.5,1.4.8,1.9.4,3.1,1,3.1,2.6h0c0,1.7-1.3,2.7-3.4,2.7A5.29335,5.29335,0,0,1,73.7125,61.1Z" fill="#fff"/>
                            </g>
                        </g>
                    </g>
                </svg>
                </a>
            </div>
        </div>
    </div>
    <!--//container-->
</footer>
<!--//footer-->


<!-- Main Javascript -->
<script type="text/javascript" src="assets/plugins/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/plugins/prism/prism.js"></script>
<script type="text/javascript" src="assets/plugins/jquery-scrollTo/jquery.scrollTo.min.js"></script>
<script type="text/javascript" src="assets/plugins/stickyfill/dist/stickyfill.min.js"></script>
<script type="text/javascript" src="assets/js/main.js"></script>

</body>
</html>
